package org.sny7.openOfflineList.gui;

import java.awt.Frame;
import java.awt.TextArea;
import java.io.PrintStream;

import javax.swing.SwingUtilities;

public class DebugConsole extends Frame {
	
	private static final long serialVersionUID = 1L;

	private DebugConsole() {
		initGUI();
	}

	private void initGUI() {

		this.setTitle("Debug Console");

		this.setSize(400, 240);

		final TextArea textArea = new TextArea();
		textArea.setEditable(false);

		this.add(textArea);

		PrintStream printStream = new PrintStream(System.out) {
			public void println(String x) {
				textArea.append(x + "\n");
			}
		};
		
		System.setOut(printStream);
		System.setErr(printStream);
	}
	
	public static void display() {
		DebugConsole debugConsole = new DebugConsole();
		debugConsole.setLocationRelativeTo(null);
		debugConsole.setVisible(true);
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				DebugConsole debugConsole = new DebugConsole();
				debugConsole.setLocationRelativeTo(null);
				debugConsole.setVisible(true);
			}
		});
	}
}
